package app.controllers.mobileweb;

import app.Const;
import app.interceptors.MobileWxMemberInterceptor;
import app.models.booking.DiningRecord;
import app.models.booking.KtvBooking;
import app.models.brand.BrandAttention;
import app.models.game.GameJoinrecord;
import app.models.gift.Exchange;
import com.github.sog.controller.BasicController;
import com.google.common.collect.Lists;
import com.jfinal.aop.Before;

import java.util.List;

/**
 * <p>
 * .
 * </p>
 *
 * @author liuhui
 * @version 1.0 2014-04-24 15:11
 * @since JDK 1.6
 */
@Before(MobileWxMemberInterceptor.class)
public class RecordInfoController extends BasicController {

    public void index(){
        String mid = getPara(Const.MEMBER_PARAM,"0");
        List<BrandAttention> attentionList = BrandAttention.dao.findByMemberId(Integer.parseInt(mid));
        List<GameJoinrecord> recordList = GameJoinrecord.dao.findRecordByMid(mid);
        int ktvCount = KtvBooking.dao.getBookingCountByMid(Integer.parseInt(mid));
        long DiningCount = DiningRecord.dao.getCountByMid(Integer.parseInt(mid));
        long exchangeCount = Exchange.dao.getCountByMid(Integer.parseInt(mid));
        setAttr("gameCount", recordList.size());//游戏数
        setAttr("attentionCount",attentionList.size());//关注数
        setAttr("DiningCount",DiningCount);//餐饮预订数
        setAttr("ktvCount",ktvCount);//KTV预订总数
        setAttr("exchangeCount",exchangeCount);//礼品总数
        render("index.ftl");
    }

    /**
     * 中奖明细
     */
    public void winDetails(){
        String mid = getPara(Const.MEMBER_PARAM,"0");
        List<GameJoinrecord> recordList = GameJoinrecord.dao.findRecordByMid(mid);
        setAttr("recordList",recordList);
        render("win-details.ftl");
    }

    /**
     * 餐饮预订明细
     */
    public void diningDetail(){
        long mid = getParaToLong(Const.MEMBER_PARAM, 0L);
        List<DiningRecord> notList = Lists.newArrayList();
        List<DiningRecord> hasbeenList = Lists.newArrayList();

        List<DiningRecord> bookingListByMid = DiningRecord.dao.findBookingListByMid(mid);
        for (DiningRecord diningRecord : bookingListByMid) {
            int status = diningRecord.getInt("status");
            if(status == Const.BOOKING_STATUS.STATUS_1){
                notList.add(diningRecord);
            }else if(status == Const.BOOKING_STATUS.STATUS_2){
                hasbeenList.add(diningRecord);
            }
        }
        setAttr("notList",notList);
        setAttr("hasbeenList",hasbeenList);
        render("dining_detail.ftl");
    }

    /**
     * KTV预订明细
     */
    public void ktvDetail(){
        long mid = getParaToLong(Const.MEMBER_PARAM, 0L);
        List<KtvBooking> notList = Lists.newArrayList();
        List<KtvBooking> hasbeenList = Lists.newArrayList();

        List<KtvBooking> bookingListByMid = KtvBooking.dao.findBookingListByMid(mid);
        for (KtvBooking booking : bookingListByMid) {
            int status = booking.getInt("status");
            if(status == Const.BOOKING_STATUS.STATUS_1 ){
                notList.add(booking);
            }else if(status == Const.BOOKING_STATUS.STATUS_2){
                hasbeenList.add(booking);
            }
        }
        setAttr("notList",notList);
        setAttr("hasbeenList",hasbeenList);
        render("ktv_detail.ftl");

    }

    /**
     * 礼品兑换明细
     */
    public void giftDetail(){
        String mid = getPara(Const.MEMBER_PARAM,"0");
    }
}
